/* This do file provides the code to generate Figure A3.3 in Appendix 3. */

global dataDir "~/Dropbox/Party_Interactions_Perceptions/PSRM Submission/Replication Files"
use "$dataDir/replication_data.dta", clear



set more off
foreach i of numlist 1 2{

replace dyad_name`i'="AfD" if dyad_name`i'=="afd"
replace dyad_name`i'="Alt" if dyad_name`i'=="alt"
replace dyad_name`i'="BQ" if dyad_name`i'=="bq"
replace dyad_name`i'="CDU" if dyad_name`i'=="cdu"
replace dyad_name`i'="Cons" if dyad_name`i'=="cons"
replace dyad_name`i'="KF" if dyad_name`i'=="cpp"
replace dyad_name`i'="DF" if dyad_name`i'=="dpp"
replace dyad_name`i'="Enh" if dyad_name`i'=="enh"
replace dyad_name`i'="FDP" if dyad_name`i'=="fdp"
replace dyad_name`i'="Lab" if dyad_name`i'=="lab"
replace dyad_name`i'="Lib" if dyad_name`i'=="lib"
replace dyad_name`i'="LibDem" if dyad_name`i'=="libdem"
replace dyad_name`i'="Linke" if dyad_name`i'=="linke"
replace dyad_name`i'="NDP" if dyad_name`i'=="ndp"
replace dyad_name`i'="NB" if dyad_name`i'=="new"
replace dyad_name`i'="RadVen" if dyad_name`i'=="rad"
replace dyad_name`i'="SDP" if dyad_name`i'=="sdp"
replace dyad_name`i'="SNP" if dyad_name`i'=="snp"
replace dyad_name`i'="SPD" if dyad_name`i'=="spd"
replace dyad_name`i'="SF" if dyad_name`i'=="spp"
replace dyad_name`i'="UKIP" if dyad_name`i'=="ukip"
replace dyad_name`i'="Ven" if dyad_name`i'=="ven"
replace dyad_name`i'="Green" if dyad_name`i'=="green"


}

capture drop dyadname
egen dyadname=concat(dyad_name1 dyad_name2), punct("-")


capture drop countryyear
egen countryyear=concat(country year)




/* Germany 2018*/


set more off

local figure=1
levelsof dyadname if countryyear=="Germany2018" & coop!=., local(levels) 
 foreach l of local levels {
 
sum coop if dyadname=="`l'" & countryyear=="Germany2018" & coop!=.

local ll2 : di %3.2f r(mean)

 
twoway histogram coop if dyadname=="`l'" & countryyear=="Germany2018" ///
 & coop!=., ///
 discrete percent xtitle("") ytitle("") color(gray) xline(`ll2') ///
 text(55 `ll2' "`ll2'") title("`l'") graphregion(margin(0 0 0 0)) plotregion(margin(0 0 0 0)) ///
 name(`ctryyear'fig`figure', replace) yscale(r(0 30)) nodraw
 
 local figure=`figure'+1
 
 }
 
 
 set more off
 capture drop partiesname
 gen partiesname=""
 
  capture drop avg
 gen avg=.
 
 local row=1
 levelsof dyadname if countryyear=="Germany2018", local(levels) 
 foreach l of local levels {
 sum coop if dyadname=="`l'" & countryyear=="Germany2018" & coop!=.
replace avg=r(mean) in `row'
  replace partiesname="`l'" in `row'
  local row=`row'+1

 }
 capture drop groupid
 egen groupid=group(partiesname)
 
 
graph combine fig7 fig4 fig14 fig5 fig11 fig15 fig13 fig9 fig10 ///
fig6 fig8 fig3 fig12 fig2 fig1 , ///
 l1(% of Respondents) b1(Perceived Cooperation Scores) rows(3) ///
 note("Dashed line indicates the average cooperation score",size(vsmall)) ///
 ycommon scale(1.15) title(Germany 2018)  
 

  graph export "$dataDir/figA3_3(part 1).pdf", replace

 
/* Germany 2019*/


set more off

local figure=1
levelsof dyadname if countryyear=="Germany2019" & coop!=., local(levels) 
 foreach l of local levels {
 
sum coop if dyadname=="`l'" & countryyear=="Germany2019" & coop!=.

local ll2 : di %3.2f r(mean)

 
twoway histogram coop if dyadname=="`l'" & countryyear=="Germany2019" ///
 & coop!=., ///
 discrete percent xtitle("") ytitle("") color(gray) xline(`ll2') ///
 text(55 `ll2' "`ll2'") title("`l'") graphregion(margin(0 0 0 0)) plotregion(margin(0 0 0 0)) ///
 name(`ctryyear'fig`figure', replace) yscale(r(0 30)) nodraw
 
 local figure=`figure'+1
 
 }
 
 
 set more off
 capture drop partiesname
 gen partiesname=""
 
  capture drop avg
 gen avg=.
 
 local row=1
 levelsof dyadname if countryyear=="Germany2019", local(levels) 
 foreach l of local levels {
 sum coop if dyadname=="`l'" & countryyear=="Germany2019" & coop!=.
replace avg=r(mean) in `row'
  replace partiesname="`l'" in `row'
  local row=`row'+1

 }
 capture drop groupid
 egen groupid=group(partiesname)
 

 
graph combine fig7 fig14 fig4 fig15 fig5 fig11 fig13 fig9 fig10 ///
fig6 fig8 fig3 fig12 fig2 fig1 , ///
 l1(% of Respondents) b1(Perceived Cooperation Scores) rows(3) ///
 note("Dashed line indicates the average cooperation score",size(vsmall)) ///
 ycommon scale(1.15) title(Germany 2019) 
 

  graph export "$dataDir/figA3_3(part 2).pdf", replace

